<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Model extends CI_Model
{
	public $table = '';

    public function __construct()
    {
        parent::__construct();
    }

 	public function get($data = NULL, $offset = NULL, $limit = NULL, $orderby = 'id DESC')
	{
		$this->db->select('*');
		($data) && $this->db->where($data);
		($limit && is_numeric($limit)) && $this->db->limit(intval($limit));
		($offset && is_numeric($offset)) && $this->db->offset(intval($offset));
		$this->db->order_by($orderby); 
        return $this->db->get($this->table);
	}

    public function get_by($data)
    {
    	$echo = array();

		$this->db->select('*')->from($this->table)->where($data)->limit(1);
		$query = $this->db->get();
		if($query->num_rows() == 1)
		{
			$echo = $query->row_array();
		}

		$query->free_result();
		
		return $echo;
    }

    public function update_views($id)
    {
		$this->db->set('views','views+1',FALSE);
		$this->db->where('id',$id);
    	return $this->db->update($this->table);
    }

	public function insert($data)
	{
		$this->db->insert($this->table,$data);
		return $this->db->insert_id();
	}

	public function update($data, $is_data)
	{
		return $this->db->update($this->table, $data, $is_data);
	}

	public function delete($data)
	{
		return $this->db->where($data)->delete($this->table);
	}
}

/* End of file MY_Model.php */
/* Location: ./application/code/MY_Model.php */
